home *** CD-ROM | disk | FTP | other *** search
- #include <proto/exec.h>
- #include <proto/graphics.h>
- #include <proto/intuition.h>
- #include <clib/cybergraphics_protos.h>
- #include <proto/Warp3D.h>
-
- #include <Warp3D/Warp3D.h>
- #include <cybergraphics/cybergraphics.h>
- #include <libraries/asl.h>
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <strings.h>
-
- struct ScreenBuffer *buf1=0;
- struct ScreenBuffer *buf2=0;
- struct ScreenBuffer *buf3=0;
-
- struct Window *mywindow=0;
- struct Screen *myscreen=0;
-
- extern struct IntuitionBase *IntuitionBase;
- extern struct GfxBase *GfxBase;
- struct Library *CyberGfxBase=0;
-
- #ifdef __PPC__
- struct Library *Warp3DPPCBase=0;
- #else
- struct Library *Warp3DBase=0;
- #endif
-
- struct BitMap *bm=0;
-
- W3D_Context *mycontext=0;
-
- int mywidth,myheight;
-
- int bufnum=0;
-
- void ClearWindow(void)
- {
- // Note: For fast 3D, it is prepared if the
- // Screen is always completely filled by the 3D Engine,
- // then no clearing is required... but in our case
- // the clear is needed...
-
- ULONG video;
- ULONG bpr;
- ULONG handle;
-
- handle = LockBitMapTags(bm,
- LBMI_BASEADDRESS, &video,
- LBMI_BYTESPERROW, &bpr,
- TAG_DONE);
-
- memset(video,0,bpr*480);
-
- UnLockBitMap(handle);
-
- // Well, we should really go without this, in the final
- // program, filling the whole screen with 3D or such...
- // Clearing every frame is slow... and most 3D Engines
- // fill the whole screen with data... but this is just
- // a simple example !!!
- }
-
- void SwitchBuffer(void)
- {
- W3D_Scissor s = {0, 0, 0, 0};
-
- s.width=mywidth;
- s.height=myheight;
-
- if (bufnum == 0)
- {
- bm = buf2->sb_BitMap;
- mywindow->RPort->BitMap=bm;
- ClearWindow();
- W3D_SetDrawRegion(mycontext, bm, 0, &s);
- buf2->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort = NULL;
- while (!ChangeScreenBuffer(myscreen, buf2));
- bufnum = 1;
- }
- else if (bufnum==1)
- {
- bm = buf3->sb_BitMap;
- mywindow->RPort->BitMap=bm;
- ClearWindow();
- W3D_SetDrawRegion(mycontext, bm, 0, &s);
- buf3->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort = NULL;
- while (!ChangeScreenBuffer(myscreen, buf3));
- bufnum=2;
- }
- else
- {
- bm = buf1->sb_BitMap;
- mywindow->RPort->BitMap=bm;
- ClearWindow();
- W3D_SetDrawRegion(mycontext, bm, 0, &s);
- buf1->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort = NULL;
- while (!ChangeScreenBuffer(myscreen, buf1));
- bufnum=0;
- }
- }
-
- void closeit(char *ch)
- {
- if (buf1) FreeScreenBuffer(myscreen,buf1);
- buf1=0;
- if (buf2) FreeScreenBuffer(myscreen,buf2);
- buf2=0;
- if (buf3) FreeScreenBuffer(myscreen,buf3);
- buf3=0;
- if (mywindow) CloseWindow(mywindow);
- mywindow=0;
- if (myscreen) CloseScreen(myscreen);
- myscreen=0;
- if (IntuitionBase) CloseLibrary(IntuitionBase);
- IntuitionBase=0;
- if (GfxBase) CloseLibrary(GfxBase);
- GfxBase=0;
- if (CyberGfxBase) CloseLibrary(CyberGfxBase);
- CyberGfxBase=0;
- #ifdef __PPC__
- if (Warp3DPPCBase) CloseLibrary(Warp3DPPCBase);
- Warp3DPPCBase=0;
- #else
- if (Warp3DBase) CloseLibrary(Warp3DBase);
- Warp3DBase=0;
- #endif
- printf(ch);
- exit(0);
- }
-
- void init(int width, int height, int format)
- {
- int flags,ModeID;
- ULONG CError;
-
- mywidth=width;
- myheight=height;
-
- IntuitionBase=OpenLibrary("intuition.library",0);
- if (!IntuitionBase)
- {
- closeit("intuition.library could not be opened!\n");
- }
- GfxBase=OpenLibrary("graphics.library",0);
- if (!GfxBase)
- {
- closeit("graphics.library could not be opened!\n");
- }
- CyberGfxBase=OpenLibrary("cybergraphics.library",0);
- if (!CyberGfxBase)
- {
- closeit("cybergraphics.library could not be opened!\n");
- exit(0);
- }
- #ifdef __PPC__
- Warp3DPPCBase=OpenLibrary("Warp3DPPC.library",4);
- if (!Warp3DPPCBase)
- #else
- Warp3DBase=OpenLibrary("Warp3D.library",0);
- if (!Warp3DBase)
- #endif
- {
- closeit("Warp3D could not be opened!\n");
- }
- flags = W3D_CheckDriver();
- if (flags & W3D_DRIVER_UNAVAILABLE)
- {
- closeit("No Warp3D Driver found!\n");
- }
-
- ModeID = W3D_RequestModeTags(
- W3D_SMR_TYPE, W3D_DRIVER_3DHW,
- W3D_SMR_SIZEFILTER,TRUE,
- W3D_SMR_DESTFMT,format,
- ASLSM_MinWidth,width,
- ASLSM_MaxWidth,width+1,
- ASLSM_MinHeight,height,
- ASLSM_MaxHeight,height+1,
- TAG_DONE);
-
- if (!ModeID)
- {
- closeit("No Screenmode requested!\n");
- }
-
- myscreen = OpenScreenTags(NULL,
- SA_Height, height,
- SA_DisplayID, ModeID,
- SA_Depth, 8,
- SA_ShowTitle, FALSE,
- SA_Draggable, FALSE,
- TAG_DONE);
-
- if (!myscreen)
- {
- closeit("Screen could not get opened!\n");
- }
-
- mywindow = OpenWindowTags(NULL,
- WA_CustomScreen,myscreen,
- WA_Activate,TRUE,
- WA_Width,myscreen->Width,
- WA_Height,myscreen->Height,
- WA_Left,0,
- WA_Top,0,
- WA_Title,0,
- WA_CloseGadget,FALSE,
- WA_Backdrop,TRUE,
- WA_Borderless,TRUE,
- WA_IDCMP,IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_RAWKEY|IDCMP_MOUSEBUTTONS|IDCMP_MOUSEMOVE|IDCMP_DELTAMOVE,
- WA_Flags,WFLG_REPORTMOUSE|WFLG_RMBTRAP,
- TAG_DONE);
-
- if (!mywindow)
- {
- closeit("Window could not get opened!\n");
- }
-
- buf1=AllocScreenBuffer(myscreen,0,SB_SCREEN_BITMAP);
- if (!buf1)
- {
- closeit("Screenbuffer could not be allocated\n");
- }
-
- buf2=AllocScreenBuffer(myscreen,0,0);
-
- if (!buf2)
- {
- closeit("Screenbuffer could not be allocated\n");
- }
-
- buf3=AllocScreenBuffer(myscreen,0,0);
-
- if (!buf3)
- {
- closeit("Screenbuffer could not be opened!\n");
- }
-
- bm = buf1->sb_BitMap;
-
- mycontext = W3D_CreateContextTags(&CError,
- W3D_CC_MODEID, ModeID,
- W3D_CC_BITMAP, bm,
- W3D_CC_YOFFSET, 0,
- W3D_CC_DRIVERTYPE, W3D_DRIVER_BEST,
- W3D_CC_FAST, TRUE,
- TAG_DONE);
-
- if ((!mycontext)||(CError != W3D_SUCCESS))
- {
- closeit("W3D Context could not be created.\n");
- }
-
- }
-
- struct MyData
- {
- int id;
-
- float v1_x;
- float v1_y;
- float v2_x;
- float v2_y;
- float v3_x;
- float v3_y;
-
- // Later we will put something there...
- // Scene description or whatever :)
- };
-
- W3D_Triangle mytriangle;
-
- void DrawScene(struct MyData *mydata)
- {
- mytriangle.v1.x=mydata->v1_x;
- mytriangle.v1.y=mydata->v1_y;
- mytriangle.v1.color.r=1.0;
- mytriangle.v1.color.g=0.0;
- mytriangle.v1.color.b=0.0;
- mytriangle.v1.color.a=1.0;
-
- mytriangle.v2.x=mydata->v2_x;
- mytriangle.v2.y=mydata->v2_y;
- mytriangle.v2.color.r=0.0;
- mytriangle.v2.color.g=1.0;
- mytriangle.v2.color.b=0.0;
- mytriangle.v2.color.a=1.0;
-
- mytriangle.v3.x=mydata->v3_x;
- mytriangle.v3.y=mydata->v3_y;
- mytriangle.v3.color.r=0.0;
- mytriangle.v3.color.g=0.0;
- mytriangle.v3.color.b=1.0;
- mytriangle.v3.color.a=1.0;
-
- mytriangle.tex=0;
- mytriangle.st_pattern=0;
-
-
- if (W3D_SUCCESS == W3D_LockHardware(mycontext))
- {
- W3D_DrawTriangle(mycontext,&mytriangle);
- W3D_UnLockHardware(mycontext);
- }
- }
-
- void initstates()
- {
- W3D_SetState(mycontext, W3D_GOURAUD,W3D_ENABLE);
- W3D_SetState(mycontext, W3D_TEXMAPPING,W3D_DISABLE);
- }
-
- struct MyData mydata;
-
- int main()
- {
- int running;
- struct IntuiMessage *imsg;
-
- init(640,480,~W3D_FMT_CLUT);
- initstates();
-
- running=1;
-
- mydata.v1_x=0;
- mydata.v1_y=0;
- mydata.v2_x=200;
- mydata.v2_y=0;
- mydata.v3_x=200;
- mydata.v3_y=100;
-
- while(running)
- {
- SwitchBuffer();
- DrawScene(&mydata);
-
- imsg=(struct IntuiMessage *)GetMsg(mywindow->UserPort);
- if (imsg)
- {
- switch(imsg->Class)
- {
- case IDCMP_VANILLAKEY:
- switch(imsg->Code)
- {
- case 'q': running=0; break;
- case '8': mydata.v1_x+=10; break;
- case '5': mydata.v1_y+=10; break;
- case '4': mydata.v2_x+=10; break;
- case '6': mydata.v2_y+=10; break;
- case '7': mydata.v3_x+=10; break;
- case '9': mydata.v3_y+=10; break;
- case 'w': mydata.v1_x-=10; break;
- case 'e': mydata.v1_y-=10; break;
- case 'r': mydata.v2_x-=10; break;
- case 't': mydata.v2_y-=10; break;
- case 'z': mydata.v3_x-=10; break;
- case 'u': mydata.v3_y-=10; break;
- }
- break;
-
- printf("%i\n",mydata.v1_x);
- }
- ReplyMsg((struct Message *)imsg);
- }
- }
- closeit("End of Program.\n");
- }
-